package com.adtec.base.cloud.commons.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.Map;

@Component
@Slf4j
public class HttpRequestUtil {
    @Autowired
    private RestTemplate restTemplate;

    public Object getParamsRequest(String url,
                             Map<String, String> params) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<?> entity = new HttpEntity<>(httpHeaders);
        return  restTemplate.getForObject(url,Object.class,params);
    }

    public Object postParamsJsonRequest(String url,
                              String json,
                              Map<String, String> params) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> req = new HttpEntity<>(json, httpHeaders);
        return restTemplate.postForObject(url, req, Object.class,params);
    }


}
